package com.example.consumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class TestController {
    //这里注入的restTemplate就是在com.sam.ConsumerApp中通过@Bean配置的实例
    @Autowired
    RestTemplate restTemplate;
    
    @RequestMapping("/hello-consumer")
    @HystrixCommand(fallbackMethod = "errMsg")
    public String helloConsumer() {
        //调用hello-service服务，注意这里用的是服务名，而不是具体的ip+port
        String forObject = restTemplate.getForObject("http://service/123", String.class);
        return forObject;
    }

    public String errMsg(){
        helloConsumer();

        return helloConsumer();
    }
}
